<?php 

if ( function_exists('register_sidebar') ){
	register_sidebar(array(
			'name'=>'sidebar160',
			'before_widget' => '<div class="sidebox clear overflow margin_b_20">',
			'after_widget' => '</div>',
			'before_title' => '<h1 class="sidetitle g_font">',
			'after_title' => '<span class="line"></span></h1>',
	));
	
	register_sidebar(array(
			'name'=>'sidebar260',
			'before_widget' => '<div class="sidebox clear overflow margin_b_20">',
			'after_widget' => '</div>',
			'before_title' => '<h1 class="sidetitle g_font">',
			'after_title' => '<span class="line"></span></h1>',
	));
}
if ( function_exists( 'add_theme_support' ) ) { // Added in 2.9
	add_theme_support( 'post-thumbnails' );
	add_image_size( 'destaque_top', 1920, 273, true);
	add_image_size( 'destaque_post', 550, 217, true );
	add_image_size( 'destaque_home', 320, 208, true );
}

wp_deregister_script('jquery');

if(!is_admin()) {
	wp_register_script('jquery', get_bloginfo('template_url').'/js/jquery.min.js');
	wp_enqueue_script('jquery');
}

function get_keywords_seo(){
	global $post;
	if(is_home()){
		return 'escolas, escolas públicas, escolas particulares, transporte escolar, produtos, serviços, guia de escola';
	}else{
		$posttags = get_the_tags();
		if ($posttags) {
			foreach($posttags as $tag) {
				$tags.= $tag->name . ',';
			}
		}
		return $tags.'escolas, escolas públicas, escolas particulares, transporte escolar, produtos, serviços, guia de escola';
	}

}

function primeira_img() {
	global $post, $posts;
	$primeira_img = '';
	ob_start();
	ob_end_clean();
	$image_id = get_post_thumbnail_id();
	$src = wp_get_attachment_url($image_id);
	if(empty($src)){
		$saida = preg_match_all('/<img.+src=[\'"]([^\'"]+)[\'"].*>/i', $post->post_content, $matches);
		$primeira_img = $matches[1][0];
	}
	if($src <> ''){
		return $src;
	}elseif ($primaira_img <> ''){
		return $primaira_img;
	}else{
		$primaira_img = "http://localhost/turismo/wp-content/themes/pp/images/default-header-background.jpg";
		return $primaira_img;
	}
}

function get_thumb_destaque(){
	global $post;
	$image_id 	= get_post_thumbnail_id();
	$src 		= wp_get_attachment_image_src($image_id, 'destaque_home');
	
	if($src){
		return $src[0];
	}else{
		$src = get_bloginfo('template_url')."/images/default-thumb.jpg";
		return $src;
	}
}

function get_posts_destaque($post_limite = 10, $cat){
	
	
	$args = array(
			'posts_per_page'=> $post_limite,
			'cat' 			=> $cat
	);
	
	$wp_query = new WP_Query();
	$wp_query->query($args);
	
	if($wp_query->have_posts()){
		return $wp_query;
	}else{
		return '';
	}
	
}
function get_template_lista_promocao($class='t_porcents'){
	global $post;
	$url = get_permalink();
	$valor = get_post_meta($post->ID,'valor', true);
?>
	<div class="<?php echo $class;?> home_list_item relative left">
		<div class="package-content-wrapper">
			<div class="relative">
				<div class="relative margin_b_10">
					<a href="<?php echo $url;?>">
						<img alt="thumb_home" src="<?php echo get_thumb_destaque();?>">
						<div class="package_alert">
							<div class="package_type normal-type g_font">Veja mais</div>
							<div class="clear"></div>
							<div class="type_arrow right"></div>
							<div class="clear"></div>
						</div>
					</a>
				</div>
				<div class="package_title_wrapper g_font">
					<div class="package_title_overlay"></div>
					<h2 class="package_title left relative overflow">
						<a href="<?php echo $url;?>"><?php the_title();?></a>
					</h2>
					<?php if($valor){?>
					<div class="package_info right relative"><span class="f_12">A partir de </span><span class="package-price"><?php echo $valor;?></span></div>
					<?php }?>
				</div>
			</div>						
		</div>
	</div>
<?php 
}

